{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import sympy as sym\n",
    "from sympy.polys import subresultants_qq_zz\n",
    "\n",
    "sym.init_printing()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Resultant\n",
    "----------"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If $p$ and $q$ are two polynomials over a commutative ring with identity which can be factored into linear factors,\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$p(x)= a_0 (x - r_1) (x- r_2) \\dots (x - r_m) $$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$q(x)=b_0 (x - s_1)(x - s_2) \\dots (x - s_n)$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "then the resultant $R(p,q)$ of $p$ and $q$ is defined as:\n",
    "\n",
    "$$R(p,q)=a^n_{0}b^m_{0}\\prod_{i=1}^{m}\\prod_{j=1}^{n}(r_i - s_j)$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Since the resultant is a symmetric function of the roots of the polynomials $p$ and $q$, it can be expressed as a polynomial in the coefficients of $p$ and $q$."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "From the definition, it is clear that the resultant will equal zero if and only if $p$ and $q$ have at least one common root. Thus, the resultant becomes very useful in identifying whether common roots exist. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Sylvester's Resultant\n",
    "---------------------\n",
    "\n",
    "It was proven that the determinant of the Sylvester's matrix is equal to the resultant. Assume the two polynomials:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "-  $$p(x) = a_0 x_m + a_1 x_{m-1}+\\dots+a_{m-1}x+a_m$$\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "-  $$q(x)=b_0x_n + b_1x_{n-1}+\\dots+b_{n-1}x+b_n$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Then the Sylverster matrix in the $(m+n)\\times(m+n)$ matrix:\n",
    "\n",
    "$$\n",
    "\\left|\n",
    "\\begin{array}{cccccc} \n",
    "a_{0} & a_{1} & a_{2} & \\ldots & a_{m}    & 0     & \\ldots &0 \\\\ \n",
    "0     & a_{0} & a_{1} & \\ldots &a_{m-1}   & a_{m} & \\ldots &0 \\\\\n",
    "\\vdots     &     \\ddots & \\ddots&       \\ddots&         \\ddots&      \\ddots&       \\ddots&\\vdots \\\\\n",
    "0     & 0     & \\ddots     &       \\ddots&         \\ddots&      \\ddots&       \\ddots&a_{m}\\\\\n",
    "b_{0} & b_{1} & b_{2} & \\ldots & b_{n}    & 0    & \\ldots & 0 \\\\\n",
    "0     & b_{0} & b_{1} & \\ldots & b_{n-1}  & b_{n} & \\ldots & 0\\\\\n",
    "\\ddots     &\\ddots      & \\ddots&       \\ddots&         \\ddots&      \\ddots&       \\ddots&\\ddots \\\\\n",
    "0     & 0     &      \\ldots&       \\ldots&         \\ldots&      \\ldots&       \\ldots& b_{n}\\\\\n",
    "\\end{array}\n",
    "\\right| = \\Delta $$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Thus $\\Delta$ is equal to the $R(p, q)$."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Example: Existence of common roots\n",
    "------------------------------------------\n",
    "\n",
    "Two examples are consider here. Note that if the system has a common root we are expecting the resultant/determinant to equal to zero."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "x = sym.symbols('x')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**A common root exists.**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "f = x ** 2 - 5 * x + 6\n",
    "g = x ** 2 - 3 * x + 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPwAAAAcBAMAAAC3wc/WAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAMkS7zRCZdiKJ71Rmq90icBAQAAAACXBIWXMAAA7EAAAOxAGVKw4bAAADWUlEQVRIDb1XTWgTQRh9+c82aRrEe+NJFKSBokdbMTe1nUOhKNQGqxFRaC5trSBdFIqC2IDY2oM0aAXpQYOiCD2YkwepoviP4B+19VRrMVSpGGd2djYzyaaki3Sgme9733vvy+zMTihgjdEdxIodBlrPEYdKaHp9q1Ot0F3BSxHWPG/gzIju+lWzpgrxGxr1KiUbOM0wV5xXIrHgkg1nTdAXjMRqF2xjVK+146FC7dJqzIeWWzVGCdfyND5q5RHjaVipo2B+LaqvQLC05NEyqbfPdbwM4un4YNQWB7SkWgiOX8qpCM+CqWZq0S8LwmVS1BWLGTttR8zfaodT7FEZPozQnzLISLug0YM2AtRZ324LNqlM79WTChBK83QHPHGlYCXujDtqJSwYyuGvDAiLV8AUEMmjkZhl157p7TITqFdTmFp39fdz4/RdYce1W2O+n7KLaH8L+BiFP47Hokof9aKI+VylvSer0qTsdrEoZUaoPnzRvp2w9oEsDlNS5+kzg+lyHV39TH8UvoG3m8d4zdQ27Bo7VEGWaGrtYMbGglG+E7gLaAZ8mfB8pFVVscxD6EW0H0/Ts7xmtu/eKx0YoZJoAjLm83PExoKW3L/pjfcD++jhJ1ohpCsqkezEZUyQBzwV7Qvw3xAEMUs0AfFZu2ZjQUuRZ/SlX8IcXT28cUvja1ugYzbKgV6dYLcRaolE22QiQUUNnxCuuJ4FjXFViykiaiULSkrRv+AKWz11TLPP8kF/vSZiwLLAzdXTfQrbvMwWTdDZfA5oyVVaAIEkrdLVG+0bzcUyRWlMAr2EbZA5zPb1WZvVSzRBZ3ORsPYVFsB9BHXQn9gXQIgMIUBkFY+TwCzuBRbRx3OzvYvufZYjpU+JVgKB6/SE61LNtIAriYDOTv4poCnXgguyyIyHEb7pXvEsBvMcENp3OJBTbxPINNlpBqFluSYsLo6PfgDCWTQRdA10njA7yFIEj70mvjd9/TMmKrRa6jmwoDwumSZ7uFM9MbkmLNqLRXoZ01uvLibTV42F1iBVeVNXNaD7nJYJ3jT8GRlYNfbpUlmT4tpDxQLd9GBnaxfLzE45cRg/obr3zrR5ZzJF9ZlmHQqynkmY7XsouZ4t5V5njeSODK1n7Pg/ov/2Jf8B6oTd7JsJTuYAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\left ( x^{2} - 5 x + 6, \\quad x^{2} - 3 x + 2\\right )$$"
      ],
      "text/plain": [
       "⎛ 2             2          ⎞\n",
       "⎝x  - 5⋅x + 6, x  - 3⋅x + 2⎠"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f, g"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAJgAAABkCAMAAABNTAlxAAAAP1BMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADFBd4eAAAAFHRSTlMAMquZdlQQQO0wRO/NZt2JIrt8bAICnK4AAAAJcEhZcwAADsQAAA7EAZUrDhsAAASpSURBVGgF7Ztrl6MgDECpWGbXF7rL//+ty6OxJlLTYLvTMwc/lA5FvAaovcZRFxe3Rn3INiUepS5Ot367fgiXGgNN4wLY5VOY7hzjGbChNeqin4i0ta1lT95oO95bUbBrb+7U3Ls+TAbLtVJm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ZhflkB6gY8GwbdOh3J3vd1VUMGnka8RqxKQRkLavc6xGTBoBaXs8x7BzSvvi2jN+jL0Yg2HnPDiQxIuhG8aPiRcjMOKc0CMthV4MuzN+TLwYgRHnhB4zpeSHLuzO+DHxYgRGnBN6zJQlYLGbx35MvHgLRkUlAwRVpWCsH69evAWjzgkUmbIMjPfjuxdjsGgNb83wMn589+It2IuHssCPN168BaPOmRlCqCoZSt6Pt16MwIhzAkWmLAFj/Rh5MQIjzpkBgqoSMM6PsRcjsPdmeBk/Jl6MwbBzQnh2ZWGG99iPiRdjsB3C91VUMGnsa8R+WMTiHSzuvrL0nIvbr/+RasJ/gLYteweu+EjCHeN/pLat+geLi0LWzT5q8AAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\left[\\begin{matrix}1 & -5 & 6 & 0\\\\0 & 1 & -5 & 6\\\\1 & -3 & 2 & 0\\\\0 & 1 & -3 & 2\\end{matrix}\\right]$$"
      ],
      "text/plain": [
       "⎡1  -5  6   0⎤\n",
       "⎢            ⎥\n",
       "⎢0  1   -5  6⎥\n",
       "⎢            ⎥\n",
       "⎢1  -3  2   0⎥\n",
       "⎢            ⎥\n",
       "⎣0  1   -3  2⎦"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "subresultants_qq_zz.sylvester(f, g, x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAAoAAAAOBAMAAADkjZCYAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEJmJZjLNVN0i77urRHZ72Yd1AAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAVElEQVQIHWNgEDIxZWBgSGeQmMDAsoCBOYGB+wAD+0cG/gMMvN8Z5BUYeP8xzDdgYP3MMF8BREJEgLLs3xm4NzCwfATpYkpgYGhnkApgYBB+d5QBAPogE3QldevOAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$0$$"
      ],
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "subresultants_qq_zz.sylvester(f, g, x).det()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**A common root does not exist.**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "z = x ** 2 - 7 * x + 12\n",
    "h = x ** 2 - x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAANgAAAAcBAMAAADxd2x8AAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAMkS7zRCZdiKJ71Rmq90icBAQAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAC3klEQVRIDb1WS2sTURT+kmaa91hEXJq4EheSiOjWitlJZRaF6EIaqKILC9m0VaE0KIiI0AhaLQjNP2hRRLGLZuVCfASUKriwSrUqWFIxKHQxnnncO2cm08S00rvI/V7nnrkzd6YF5Jg8pEm8GRAdPNO2PFpK9rYN/UvgLt6sH9tuWWop8Gf9UAfOV6RKPvGioQWylqOmIz99Mp1LnzCR9qnaZ2gh+aTiDZ/MRqR5uSSrjlaJnJWCau5U0o2DZd/Sz0DE2c6kJ7NrYWqq7NEkvTq4X2IPiBY8gkVHAMdJeDOvdF2v+dU90aDUMJ3280h76q9PALFZYe3FbgGt+RyQ5MojiygLHzQkNcQq3HRwsBzscZiD1CpSmk0Dx+YOOo6BysBNrtjNgHHqtIjkKjcdvGPugVjTEQl1Z/FMCDFdrwss5mBRIGPmzUKNdZvN6DqvkjhcwWki+bHLF13LikAXoIy+23PH4rwZKapztOw8y4oVjNmWgw0cIFJOLKu93Bb4HnASL4tLFvc0y5RFTMwsKyRjtuXAKvroQGrRRrzEbRsrdF9vY1p7bHFPsx9NFSzLPVumD9QX2hlCWWkqx1doLPUYQrgX0HDU9G7lct9zObo0GnRA6HkXDOgaImuK/cY6K0cI23JkzdgZsK1o+t4f1byG30J274ze0eYhs27LlGlnZrOUuRF3gNhAjX7oVtvD1SxewDVhyNnJSskAlkx/VF4DcW0cYc1lWyRVAB6G6xi2qKvZTuCCt4RluWXLdBovAZnZw7jBXYHnCwiuddUjVUvgzSLfpoYWlV8iac48ywwhJyrIaDg1mj9fZa6E12ehvB0eeW4LotnQTF81RN/NRay47gfPyjXo/NlL0BcklmZ6ayiaOSnfF8ax3ShURHfZLbVgJ5q8aJPSQhjQEKi08NtZ+XYB7r8g8p4LHeJqJ/mPFO7vpGAT2YTxvOjt3JJxxexyf0t6of2/yf/3Ov4CP+2+nhhj8lkAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\left ( x^{2} - 7 x + 12, \\quad x^{2} - x\\right )$$"
      ],
      "text/plain": [
       "⎛ 2              2    ⎞\n",
       "⎝x  - 7⋅x + 12, x  - x⎠"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "z, h"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAKIAAABkCAMAAAAynRuAAAAAP1BMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADFBd4eAAAAFHRSTlMAMquZdlQQQO0wRO/NZt2JIrt8bAICnK4AAAAJcEhZcwAADsQAAA7EAZUrDhsAAARLSURBVGgF7ZvrmqMgDIapWjtbj931/q91BU8JfgiMsdNnF3/MWAjJ24DUfLbqNp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q/GBXQpRIfspiyqJEBiR8pLWYsiiRAQkfbC2COlsiRowPgMAQQZ3tcB9U4u/H+ocBBIqI6ux9mPFuJPKL/rOPkGEIgSKiOhshjm0hd9tgqHcYQqCIETW5NxbgC3lnCIEgwvILh7oqixCBIMI6+72IEIEhhtfkF020r9SHWT6RRfRU36MMQASSRVhnn0AEQ73JR7IARUR1Noijm7yx8DjvMIRAEad9k397Hoe6DBEhUERUZ78ZESEwRFBnQ8TAEt8eGzIMIDBE2+dnvE6IEvOQsvhfZfHjf2Ve6t9yF4X3h8ESsxbnw/zKvCjUX4xyQxa1ycz1AAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\left[\\begin{matrix}1 & -7 & 12 & 0\\\\0 & 1 & -7 & 12\\\\1 & -1 & 0 & 0\\\\0 & 1 & -1 & 0\\end{matrix}\\right]$$"
      ],
      "text/plain": [
       "⎡1  -7  12  0 ⎤\n",
       "⎢             ⎥\n",
       "⎢0  1   -7  12⎥\n",
       "⎢             ⎥\n",
       "⎢1  -1  0   0 ⎥\n",
       "⎢             ⎥\n",
       "⎣0  1   -1  0 ⎦"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "matrix = subresultants_qq_zz.sylvester(z, h, x)\n",
    "matrix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAABMAAAAOBAMAAAA/Njq6AAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAMt2rmYlmIkR2uxDNVO+L8+I6AAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAh0lEQVQIHWMQMgkNDWB3WSXAwJD///9/g80MrD8YGNwZGJgZrBkY3jEwBDAwBDI8YmCwB6pg4JjAcH4DhMkF5DIw6G8AEmEgFsdXIMH9AcRkMgASnAdATBcQwbQASHA6AAmG/SCpKwzsBQwM8kABRgcGTiDzPpBZFBpiBJSru8DAcP7//08MAOXiHWpRp63NAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$72$$"
      ],
      "text/plain": [
       "72"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "matrix.det()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Example: Two variables, eliminator\n",
    "----------\n",
    "\n",
    "When we have system of two variables we solve for one and the second is kept as a coefficient.Thus we can find the roots of the equations, that is why the resultant is often refeered to as the eliminator."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "y = sym.symbols('y')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAa0AAAAcBAMAAAAgmf1gAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAMkS7zRCZdiKJ71Rmq90icBAQAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAEqElEQVRYCd1XTWhcVRT+ZiZv/vMSRNxm3FhczaioCymOOOBCKm9RiC5CR5LajcHZNLEFyeBC/ANnoa0VsUEsLhsUUdpFZiUoIgMW/8Egaq1UieJgIcJ4/867592ZN+nL0IW5i/fOPd/3nXu+d++8lwDhKCweDeMbH5y6J0iwyCS9vY5LCVaakFpoT9cTlNhLbzeZ+r9irp1gqcmofjt1LUGFRL3lVOFUzdT/Ea9UEiw1GdWv5P9KUCFRb+merDxlz/mmDROsuUdqqZ9ImKS3N2XlY7b8ZRve+MhvJVojSW++2J+8fWyF5nWu9NziHdfJHEM75WAvnLnPyfDpUG/jesg1ASb4mBcaE3s9nK2MwRlUOscmkbDcjEyRb2KzG03x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h9N1L/KPNe/BxUjnidOfWqdZzP0q7o1B3HQM02u5xCRzv5uJ1cdh5Z5Y4btdVjmwMrsLg+AYZpnwPd3Tq4/H6uIwX3Z8OFb2vwU+kZ2Lj+w+G/maMvTePrOFbLDfHFk//wEkcWXbNbjf6AAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\left ( x^{2} + x y + 2 x + y - 1, \\quad x^{2} + 3 x - y^{2} + 2 y - 1\\right )$$"
      ],
      "text/plain": [
       "⎛ 2                       2          2          ⎞\n",
       "⎝x  + x⋅y + 2⋅x + y - 1, x  + 3⋅x - y  + 2⋅y - 1⎠"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f = x ** 2 + x * y + 2 * x + y -1\n",
    "g = x ** 2 + 3 * x - y ** 2 + 2 * y - 1\n",
    "f, g"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "matrix = subresultants_qq_zz.sylvester(f, g, y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAToAAABMCAMAAADKkIsGAAAAPFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAo1xBWAAAAE3RSTlMAMquZdlQQQOkwRCKJZt3Nu+9spI9gpgAAAAlwSFlzAAAOxAAADsQBlSsOGwAABclJREFUeAHtXNmCpCgQpLx2tsRr/f9/3QQb5L6ZcmrwoUElM5KQq4xGhKoduN/7qZr3Bzh+nfToioeCZ4S6rbjbzztcL8YQep39AMdYPKQVqHud8OfbjoXw1Z2kdq86dVvfCM0n/PnKY6lJHWFsPN2D3dz3+17p0Xmf2NTjBaeCJ1E3Hm46xJDXQTzT8hMZYXFMy4wB1+CUCxsMUhMZVlKOAOp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B4HApSnn7uoy5L5OUhXxmbSq1UCCXL1DYAHoeClKef+6jjqBUzSoX+FKQnUPf7VO2iSE+grmIzq+m6UZfMbqOuUZfMQLJha3WNOp2BJmHrnIRdaRJ2GE+GUk3CNpASdqn6FvCPTxNZKrKPRK+EDf8+v6ftS4TddMEb2EvJynJ143dhy/buM4+EPZP3nONp+Wd8k2uRhEDqysnKSkCRu7AVa8+pT8Ie6Bank+5m9rgitxUSAqkDw5yX3va44ndh232pd7wS9vuAf+mZzojdOiIJn6Yufhe2SpD13C9hU9OoDvsk6q6K013YVg4ibsRL2NNKNxILhi64x1FHd2G7Ig69Fy1hz3ilH50SDV1gj6OO7sJ2RRx6L0XCxmTA8xmyAAKoMyi4ohXzVCa9dmGX8JUgYSN0wAdvNEMDASRAkYRPTxMknFtFLkFfhIR9bWDef3ZhuwxZYM+iTlCRWYA5aYyEfVKl/Ic6pyGL6FHUcRWZRZeTRkrYB93AvsJn4nyGLKgnUcdVZBZcThorYdNN0yN0VK8hiyqFumRZmYFaUq4iW+5HXY6VsNG7h0/AkV8U5v3nKrhMQvg0ofr5E8+LiuV/F3VNwn5Gg/+7Wl1Rzht1yXQ26jKpq/RJ5+Sonm7IP+kM76rIAeubdoQxQD/pPAzofxopSUWPYvBTAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\left[\\begin{matrix}x + 1 & x^{2} + 2 x - 1 & 0\\\\0 & x + 1 & x^{2} + 2 x - 1\\\\-1 & 2 & x^{2} + 3 x - 1\\end{matrix}\\right]$$"
      ],
      "text/plain": [
       "⎡        2                        ⎤\n",
       "⎢x + 1  x  + 2⋅x - 1       0      ⎥\n",
       "⎢                                 ⎥\n",
       "⎢                      2          ⎥\n",
       "⎢  0       x + 1      x  + 2⋅x - 1⎥\n",
       "⎢                                 ⎥\n",
       "⎢                      2          ⎥\n",
       "⎣ -1         2        x  + 3⋅x - 1⎦"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "matrix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAJ8AAAAUBAMAAABhQvLIAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEM3dMnarIkSJZlS7me8N5bApAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACQElEQVQ4EY1VPWtUQRQ9bzfrfqpDJIqNLGuIFhZLRFJIdP9BNkUEi7CVpBIfWPiBwoLY6iqkEBSXWAQCwhMRO0kn2CSVoChYWoiuH2m00Hvv3Jnd55sVB/bOuefcOW/mzZtZINOuZhglKrEFxf64ivWQUNwMscKtWOVaqKB4736CXfrIVEEuRAIvDDBpC4+k6jW5jupPRHXNRrvHo4nD0fkLZFhuc17Zdqz0z2zWSfAdWE1JNpkLcER1yDD6wFo+5uibGt7qRt+AQ572oNj0MAXYEEeZupjioYbgJSPX9WK0tHKTJ1zYppko9iIBMXzAzDL9ps5cPtvmBEPDfT16KTRa20E8as8SrvUBh53GvRiuMXpFT+xVTuTrnAwNr8wber914TjcwUPznPp8MsReJCCGT5k5SRMx5a/V2Mp+yeWPtOwmJo9zm4bBMSnY04XH0WHWZlssiOECIxoXIbfJEHcbjVONxoxgfDaYGFgocUciGwIWC6EhZQjsbTtRZ3gJ2EpShhM/pISXDMVuDPdieIMRLRlYaHHkpoa/DRuWmpak+KQwwCL1vCkOe5GAGLpNqZoOCsbKavgJOB2PbErpV20gh5423uOM4Rtm6Nu5nWzB3SFquIHqDrC758ZE5xaXNzihSXvsROpff5npA9PM0Lr3L029pVSaGpbev+vSh91Cpo05elxnT1H46Fmfv06RkMHLwZYHL4cDVrNxdTRRXIsDpKX0+no5tiCqB6R/XLDqFLxgxSk8Gbd9mYf911/AH734eeMHxXpdAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$- x \\left(x - 1\\right) \\left(x + 3\\right)$$"
      ],
      "text/plain": [
       "-x⋅(x - 1)⋅(x + 3)"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "matrix.det().factor()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Three roots for x $\\in \\{-3, 0, 1\\}$."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For $x=-3$ then $y=1$."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAO0AAAAmBAMAAADaTAHLAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAZnbNRO8QMqsimd27VInIquLFAAAACXBIWXMAAA7EAAAOxAGVKw4bAAADGElEQVRYCb1XTWgTQRT+0jTbbDdJA+LZRRG0l+YgqIjQmwfBRBG96WIVekvPXhLwol66lx60lQZ6sGDRgAeFouhFq3joxZOIRfDSg7+l4im+N5NmZjY/u5fMI5n93nvzvW/nJ7MbAEgVqbFns3tSh/aAnetoSeqMXrKjxyrb7wPgiNS7MSevFtpCmKXBpuW63rYg2JbwwrF/gLvLLiNb5k27O6QlRpqu21JlnTyPtRZQsxxSY808n6TS3Dyirz3bZqlUhZoLvURdueW6U6m42RnMTDW4JC+y+1cvfn/trXCX9KCB7xhetzOYeQ5nmHKFxvxT4zp1/Jhm/6QWVPBjAMwotycayBw7/fkNs24B402Nng2QqZAvp0NLMHTuzgdAwWfc1wYzM62WGOYU4L3SamSayPK8e6EWVHAqIHW+r/6WjPklxERDK5LelbqLWkyDrItjWqAbJmPWNjHhm2SPf9iTNK5JHwuBmRO64pdgxjUvGbNaBH0MK2+R+5rWMV8BLYNhQnefEYo6yZg02OWI7nOu9AJ4MF7Ch0hVofspEjTdZMyJLdBU06SeWid7Okfbu8F1LgJBxsdvgjOcWT/OUQjdmoBGo+gJmbSpauZ4aX3ISBflYMw4UijUT5cpbUvGJF1znvMN3KMKNFtYwUhlr1r7KnTPRoKmm4xZ3ULV14k3gaPk0+7ABnJ1PUVY6MbuqwRMGiwtsTL35ffVJrnb9F1D2VyCtu5jyjl/FMdEcUzZmzZVpq4R061Wi3V5Lme/Pgm1FMHVqyfoTsQWWw/MVMeLZYqe5WnkSh2OAp5QXFEBhdwm47zooKIdFMsUPQ8EKFQ6HAXodM+WnB0VUEg+FwoqYKJYpuj+rf3CY3LJewevmPO7whSQz8FrvVIiFscUnehwcn71KrGE0YMPeyXojtiKPXMcjGNyH6G5wShqg99Wor11Pwkzz6/O+3WWHUxHP1DdtCOmqWR4mUZY3K4dFnKX7YqS2nmhOPjAHcJNtWdY/GsYQvm+JRdCkXKe9e0xlITDz0q2RakvneG3Od7NbO6cvFpqr7POf3OSvg90eF49AAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\left ( - 2 \\left(y - 1\\right), \\quad - \\left(y - 1\\right)^{2}\\right )$$"
      ],
      "text/plain": [
       "⎛                    2⎞\n",
       "⎝-2⋅(y - 1), -(y - 1) ⎠"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f.subs({x:-3}).factor(), g.subs({x:-3}).factor()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAD8AAAAUBAMAAADIGvgZAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAIma7zZnddlTvRIkQMqvFy5UvAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABJ0lEQVQoFX2Sv0vDUBDHP/nREpJXLQiuxrE4+GuXuDlmcHOpi3R0ETfJf1BnQXByNYjSSciiUhzMf9D+A4KDoqCI92wDeWnrd3h3ufuQu3f3wAqZqWWdWYD767sJRu2t5Mw1Jb4NOzxoz5CbqH1UBHaMfUognqkW3EAP6k2cId63mYYt6Gb0YRHmh/ifVeAHrhLcC47gOcb/qADqXYBDgpgNWEppfFUASwKDFDuiI0A8BZA/COC1Ofu3RONVA9KkN63JboIAUsJZw5645iasZvht3aQMqhZVmqQFu5KKuJVMh36u3kyknqhzqKVcSvzp+AUOMoNQvZMc3FyPeiSvcMqczFmWNVJQThS+LIv18cdjESxZvW79YP4Ujm3ZOLqsFcoxQ/LkfgFOMUE70U7oaQAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\left ( 0, \\quad 0\\right )$$"
      ],
      "text/plain": [
       "(0, 0)"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f.subs({x:-3, y:1}), g.subs({x:-3, y:1})"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For $x=0$ the $y=1$."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAALsAAAAmBAMAAABuRvfEAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAZnbNRO8QMqsimd27VInIquLFAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACsElEQVRIDbWWz2sTQRTHv2mSrdskm4B48eKiCNJLcxBUvPTuIauI3uxiFXpLwD9gA17Ui7n01EoCBVuwaFFBpQh6a8FDL55UGgQPevIXiqf63szuJJv9YVcmj2Tej5nvZzdvJ5MAQK5Gg3ZbCIjHgkCrL9QlrnBJK5Zh1vp94ITEXm9px3/GTSAve35LOx0v4HVg/mLw5B/9+KfozgLivvNt/Xhg1wU8eqPbGQf+MUHzNg0PxkG3ekTNOTRc+C+8KbdFVJsTzTjME+ZPev+OLtlHZTlxzW2aKfQLLXJX6BN8TVj41k2YEOUzsZOsmaeZGx/eU8Sbf2qDfNSMO3fdaFVVcj0VDgKpsWxgbm+PyzNA6RUHMTbjxhSDUkl0OMiUZ43hqHS3g2pPZeEgFb8UXhtkQnMyyODtoGpTZkzbWHRVWQSp+OkUzRfFadZALzrhKg43KmSp+NcpmoMKQ7feZfy9qTreqKoMUvEvUzTvFKja5/4AbtHGd/Lzm2ynxHwUb5zl2Sctmr6YovGEnAd6rh7fPRru5OjXK4rnhb4RPlETwovmYAUTTiD1fSqempOoOadAzT6aNmdbKLfZD1kqnh5tombwaOnWqf1k62iIJnHsG+GNH0Ey6nnzxWuAh2oxPddim7OFj486qiqCtbnTNWy64aLKuAEJGsidwUsbsyjXpWZFuvBYGbmmmi2JiViNuaFWHXFhOZQdqBt0NkfNipZkhY60RI2tRJ+ACv+el2rlQVHNAleH4nC4najhA9m353R0fKO4cHQ1KIV8LZQNJ8uJmm21TKC3VJol+MePoUBV+C/OoSzUTGvpIAOaO5k0GRYXubcTfI2x2HFBvTwWNkHPC/DgjNB7Hb8t4r+aXrKgLXaEM56NgU1fKD602ZbkZWSibSzzvmEzW9LrHa8x7i/1GZLq14Wu0gAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\left ( y - 1, \\quad - \\left(y - 1\\right)^{2}\\right )$$"
      ],
      "text/plain": [
       "⎛               2⎞\n",
       "⎝y - 1, -(y - 1) ⎠"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f.subs({x:0}).factor(), g.subs({x:0}).factor()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAD8AAAAUBAMAAADIGvgZAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAIma7zZnddlTvRIkQMqvFy5UvAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABJ0lEQVQoFX2Sv0vDUBDHP/nREpJXLQiuxrE4+GuXuDlmcHOpi3R0ETfJf1BnQXByNYjSSciiUhzMf9D+A4KDoqCI92wDeWnrd3h3ufuQu3f3wAqZqWWdWYD767sJRu2t5Mw1Jb4NOzxoz5CbqH1UBHaMfUognqkW3EAP6k2cId63mYYt6Gb0YRHmh/ifVeAHrhLcC47gOcb/qADqXYBDgpgNWEppfFUASwKDFDuiI0A8BZA/COC1Ofu3RONVA9KkN63JboIAUsJZw5645iasZvht3aQMqhZVmqQFu5KKuJVMh36u3kyknqhzqKVcSvzp+AUOMoNQvZMc3FyPeiSvcMqczFmWNVJQThS+LIv18cdjESxZvW79YP4Ujm3ZOLqsFcoxQ/LkfgFOMUE70U7oaQAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\left ( 0, \\quad 0\\right )$$"
      ],
      "text/plain": [
       "(0, 0)"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f.subs({x:0, y:1}), g.subs({x:0, y:1})"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For $x=1$ then $y=-1$ is the common root,"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAQ8AAAAUBAMAAABhZ6XhAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAIma7zZnddlTvRIkyEKtZsEGBAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAC7klEQVRIDY1WPWsUURQ9M/u9m9msBEWxmYA/wGgjIjKBJYVYLCRWapxCghCQtQiWdrbZIlUgsI22m0aDpDCNtVsIYhOjnZ1CwCAu673vvcm8O28meIt3z733nLNv5xvwQiRhwaRl8nymzpZemO2Y2u9o4IWm4SS2VvZzwPnlW2pOsCDaxq9gjFzl5f0bwDctySWoEVsr+0UER3g/5OaimmSX+g4QRNmurPOUXg+bIT5pYh4BSKzZ3u+hPUZjQHyCVtT7ujhcnRDYsyYulEozr51gNkZL2UiCa0321Q4aMdp/SU3QioSNGm/kizVxoVSaeXMbXyMEAy4lwbUm+wtAeaI3QtAKyS4PrZEDpTId06nBHS4lwbUm+w0lq/K/Jhhs9HFprFqS3eqpZsEilaekYJ3gGy4lwbUm+2tKNtqlRLBVH+CF6kCy/Uh381epTDje24cEr3ApCa61H+EJ8/CUF4IXKxGuM6Yruq+zvkbqsalyk1SmlHdD4CWXkuBak/028yrqwBMcN/r4TY1Wt7u01e0e8VBdrDM/GYoIltYoHh9Q01JaXaCxA3xkkUXItSZ7tRE6hZqN0XiGbyAKue2cjWiaWtkkVZqB10HpJN2IRXCtyZ5PTb2Hc5QYrqA20EaS3Yx1N3+VSsOZnaiNvOZSElxrsueL9QPwjBLD2ygdUaKQbD/iXlFIpWE1rqL6K71Yz7T2I767vPX91ZjUfKMtYxRSopAbqezSvX2sJ+4qlWbuh9jsA/e5lATXmuzpyJWn02lMbD6Ih3uPOpQoEnblx/F34hxQa23Mg5yQyoTw6t5Ngne5lATXmuyth6+GK8YnYetSPRrrZo+GkSapTPuEvJhLSXCtyd56HRFsR8EfFlIE4lfVS6+lJ+4qlWJ++tI705rtF1LdAqphqZ/WKdKfAZ/TRgYVK81nQDGBrZW99ckyh+bzB5mf0GVJHZ4wd8bNYqX5n8UEtlb2XshOKrxQZ3edd1ui44WiTIv//lT8By+sy4Yb1UdQAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\left ( 2 \\left(y + 1\\right), \\quad - \\left(y - 3\\right) \\left(y + 1\\right)\\right )$$"
      ],
      "text/plain": [
       "(2⋅(y + 1), -(y - 3)⋅(y + 1))"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f.subs({x:1}).factor(), g.subs({x:1}).factor()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAD8AAAAUBAMAAADIGvgZAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAIma7zZnddlTvRIkQMqvFy5UvAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABJ0lEQVQoFX2Sv0vDUBDHP/nREpJXLQiuxrE4+GuXuDlmcHOpi3R0ETfJf1BnQXByNYjSSciiUhzMf9D+A4KDoqCI92wDeWnrd3h3ufuQu3f3wAqZqWWdWYD767sJRu2t5Mw1Jb4NOzxoz5CbqH1UBHaMfUognqkW3EAP6k2cId63mYYt6Gb0YRHmh/ifVeAHrhLcC47gOcb/qADqXYBDgpgNWEppfFUASwKDFDuiI0A8BZA/COC1Ofu3RONVA9KkN63JboIAUsJZw5645iasZvht3aQMqhZVmqQFu5KKuJVMh36u3kyknqhzqKVcSvzp+AUOMoNQvZMc3FyPeiSvcMqczFmWNVJQThS+LIv18cdjESxZvW79YP4Ujm3ZOLqsFcoxQ/LkfgFOMUE70U7oaQAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\left ( 0, \\quad 0\\right )$$"
      ],
      "text/plain": [
       "(0, 0)"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f.subs({x:1, y:-1}), g.subs({x:1, y:-1})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAD8AAAAUBAMAAADIGvgZAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAIma7zZnddlTvRIkQqzLsm4+cAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABMUlEQVQoFXWSvUoDURCFv40xxOxNWBCs1zJY+FcLsU+Rwso0sRHLNFYi7gtIehFJldYgStrtgpXiC5gXEMUfUET0XJOV3Ss5xc4w5+PO7J0LXshULVpnHoYH2/8Y01waUQ5U34QG5cgl8pHZwdQg16AY4inLqgqXMIBCgL+CaWVt2IBOzDUsQOkl9kMX+ILziHyXfTn3zxeub94EtPEbrMnyv+su4H3CY59cjT1Zx72PrkJank4QUGxxoh+55eg07SqftKg8WWAuoPLuAGjIToQAtbiReecC67AcU2rZIXUCqy5QhS11r3Gle6iTa5vXLFKIzBnM9ump/tDUsnbjDGEGhyPIj+xVj1VMkjSne9ayxvLTRpJrWX/jDZNiKtp12wfzq3AS02HGtvVCfaZIT+4HIgs9RHw/mCAAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\left ( 8, \\quad 0\\right )$$"
      ],
      "text/plain": [
       "(8, 0)"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f.subs({x:1, y:3}), g.subs({x:1, y:3})"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "Example: Generic Case\n",
    "-----------------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "a = sym.IndexedBase(\"a\")\n",
    "b = sym.IndexedBase(\"b\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "f = a[1] * x + a[0]\n",
    "g = b[2] * x ** 2 + b[1] * x + b[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "matrix = subresultants_qq_zz.sylvester(f, g, x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAALoAAAAZBAMAAAB0qCmCAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAIpmJdu8QRM1mu90yVKvMIHo8AAAACXBIWXMAAA7EAAAOxAGVKw4bAAACkElEQVRIDa2WP2gTYRjGn/SaS+Ll7NHBSTRQEamgMXR0CAniqiDiH8RDcHEwAXFzCFIkULRFR5fSQRwVhCqCRqdujYOLUpshg+LSUkgRjPF93++73J8cIaV5h7v3vuf5fnnyfpdSQMqYPa6afV/jSGfwc99cBYgjvca6Mx58HGkVR6vjoceTNt3x0IE40ptxwRFDMnLAneujfsIwZxzpKYOfjEof5owhpfKpBtAdmR5y2sXAvjjS2sY3F6lOwDW0DTtD9DjSzV4PMF4NRQbEsDNEj5ASM8cuq43pdqkZQOjW1zFdOOfKatjp0X2nr9930lsKVHlkbqOwogBqia6iT87lgdRFLALZGiBObqQ8eoRULgPmVUwsKxf9DHYM52BNPemr0p/hB3B7CbPInqL5sVMaMWl6hJTJ2y1MdGAVIdlOwNyxnOw2bTEX3lO9bUDrq5hycdrlX4pNdHZKQ4dVry9cqddbnhNrtF1IVXSQXEalAcn2EKmuVU3skuxXknXzL5JNXAPdBcpOTSenzi5OfP5NK6wT9QYqeWwCku0PB4Udfi9Fp+9jLXFcOiHOLk5upDRdkfCd1linP7rvUGnipX1Isu3yZHlOwRL9MI/P7OJA7YvQxTlAZ5IjdNbXeY7pYuaDIdnwCyvELQTZ6OvJIubxvJUXujijdCFB6KxT9ksw22ePnM/K0d4qUfRMLkwXneY9VcXd8qd2VejijNLFqeis09z1CVJ2yiZ1Dw/CeHmSc1HrPjQyd72N585l8TsjpbJxm3288UKtha4lft9V2Reijel4Gt89+mSO3ndV/WzJXm9LrwVvxoz3P0Pi5L+iKP0m6KPeo6NQcLUUyBYx7/nx6+AOP9ugtreV6Y9tf8N/+R7ldlDvKZsAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$a_{0}^{2} b_{2} - a_{0} a_{1} b_{1} + a_{1}^{2} b_{0}$$"
      ],
      "text/plain": [
       "    2                             2     \n",
       "a[0] ⋅b[2] - a[0]⋅a[1]⋅b[1] + a[1] ⋅b[0]"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "matrix.det()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [conda env:sympy]",
   "language": "python",
   "name": "conda-env-sympy-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
